import os
with open('groups.txt','r') as f:
    a=f.readlines()
group_list=[]
for line in a:
    line1='"'+line.replace('\n','')+'"'
    #print(line1)
    group_list.append(line1)
#print(group_list)
for x in group_list:
    print(x)
    f = os.popen(r'net group {} /domain'.format(x), "r")
    d = f.read()
    try:
        names=d.split('-------------------------------------------------------------------------------')[1].split('The command completed successfully.')[0].replace('\n','')\
    .split('                 ')
    #print(names)
        names1=[]
        for name in names:
            y=name.replace(' ','')
            if y=='':
                pass
            else:
                names1.append(y)
        print(names1)
        with open('g.csv','a+')as f:
            f.write(x+','.join(names1)+'\n')
    except:
        pass
    

    
